package main

import (
	"fmt"
	"sync"
)

var instance *Singleton
var once sync.Once

type Singleton struct {
	value int
}

func GetInstance() *Singleton {
	once.Do(func() {
		instance = &Singleton{value: 42}
		fmt.Println("Initialized instance")
	})
	return instance
}

//func main() {
//	var wg sync.WaitGroup
//	for i := 0; i < 5; i++ {
//		wg.Add(1)
//		go func(id int) {
//			defer wg.Done()
//			inst := GetInstance()
//			fmt.Println("Goroutine %d got instance with value: %d\n", id, inst.value)
//		}(i)
//	}
//
//	wg.Wait()
//}
